package orm

import (
	"fmt"
)

// 相等条件
type condEq struct {
	field string
	value interface{}
}

// 不等条件
type condNotEq struct {
	field string
	value interface{}
}

// 相等
func Eq(field string, value interface{}) Cond {
	return &condEq{
		field: field,
		value: value,
	}
}

// 不等
func NotEq(field string, value interface{}) Cond {
	return &condNotEq{
		field: field,
		value: value,
	}
}

func (c *condEq) Not() Cond {
	return NotEq(c.field, c.value)
}

func (c *condNotEq) Not() Cond {
	return Eq(c.field, c.value)
}

func (c *condEq) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v = %v", colname(c.field), param())
}

func (c *condNotEq) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v <> %v", colname(c.field), param())
}
